#include "unp.h"

void server(int in,int out)
{
   size_t n;
   char buf[MAXLINE+1];

   int fd;

   if((n=read(in,buf,MAXLINE)) ==0){
      err_sys("read error");
   }
   buf[n] = '\0';

   printf("server receive:%s %d\n",buf,MAXLINE);

   if((fd=open(buf,O_RDONLY)) < 0){
     snprintf(buf+n,sizeof(buf)-n,":cant open %s",strerror(errno)); 
     n = strlen(buf);
     write(out,buf,n);
   }else {
      while((n=read(fd,buf,MAXLINE))>0){
         printf("server  %d read:%d\n",fd,n);
         write(out,buf,n);
      }  
      close(fd);
   } 
}
